/*
 * crash_oscillogram_packet.h
 *
 *  Created on: 20.07.2013
 *      Author: SpirTanol
 */

#ifndef CRASH_OSCILLOGRAM_PACKET_H_
#define CRASH_OSCILLOGRAM_PACKET_H_

#include "packets/data_packet.h"
#include "global.h"

class CrashOscillogramPacket : public DataPacket
{
	enum Reg
	{
		R_TIME,
		R_CODE = R_TIME + 2,
		R_COEFF_CUR,
		R_COEFF_VOL,

		R_CUR_PHASE_A,
		R_CUR_PHASE_B = R_CUR_PHASE_A + 64,
		R_CUR_PHASE_C = R_CUR_PHASE_B + 64,

		R_VOL_PHASE_A = R_CUR_PHASE_C + 64,
		R_VOL_PHASE_B = R_VOL_PHASE_A + 64,
		R_VOL_PHASE_C = R_VOL_PHASE_B + 64,

		R_SIZE = R_VOL_PHASE_C + 64,
	};
	ushort oData[R_SIZE];

public:
	CrashOscillogramPacket();
	CrashOscillogramPacket(const CrashOscillogramPacket *packet);
	~CrashOscillogramPacket() {}

	inline uint time() const { return *(const uint*)&oData[R_TIME]; }
	inline int code() const { return int(oData[R_CODE]); }

	inline double coeffCur() const { return double(oData[R_COEFF_CUR]) / 256.0; }
	inline double coeffVol() const { return double(oData[R_COEFF_VOL]) / 256.0; }

	inline int curPhaseA(int idx) const { return int(short(oData[R_CUR_PHASE_A + idx])); }
	inline int curPhaseB(int idx) const { return int(short(oData[R_CUR_PHASE_B + idx])); }
	inline int curPhaseC(int idx) const { return int(short(oData[R_CUR_PHASE_C + idx])); }

	inline int volPhaseA(int idx) const { return int(short(oData[R_VOL_PHASE_A + idx])); }
	inline int volPhaseB(int idx) const { return int(short(oData[R_VOL_PHASE_B + idx])); }
	inline int volPhaseC(int idx) const { return int(short(oData[R_VOL_PHASE_C + idx])); }

	CrashOscillogramPacket *clone() const { return new CrashOscillogramPacket(this); }

private:
	void init();

};

#endif /* CRASH_OSCILLOGRAM_PACKET_H_ */
